package com.binarysearch;

import java.util.Arrays;

public class Solution2300 {
    public int[] successfulPairs(int[] spells, int[] potions, long success) {
        int m = spells.length;
        int n = potions.length;
        int[] res = new int[m];
        Arrays.sort(potions);
        long[] arr = new long[n];
        int index = 0;
        for (int x : potions) {
            arr[index++] = x;
        }
        for (int i = 0; i < m; i++) {
            int l = 0;
            int r = n;
            while (l < r) {
                int mid = l + r >> 1;
                if (spells[i] * arr[mid] >= success) r = mid;
                else l = mid + 1;
            }
            res[i] = n - l;
        }
        return res;
    }
}
